package cn.vcjf.weapp.api.user.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.vcjf.weapp.common.web.TableResult;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import cn.vcjf.weapp.api.user.entity.UserDiscount;
import cn.vcjf.weapp.api.user.service.UserDiscountService;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhengzihang
 * @since 2018-09-25
 */
@Controller
@RequestMapping("/user/userDiscount")
public class UserDiscountController {
     @Resource
     private UserDiscountService  userDiscountService;

     @RequestMapping("/addUserDiscount")
     @ResponseBody
     public TableResult addUserDiscount(UserDiscount userDiscount){
         userDiscount.preInsert();
         boolean b = userDiscountService.insert(userDiscount);
         return TableResult.Result(b);
     }

     @RequestMapping("/updateUserDiscount")
     @ResponseBody
     public TableResult updateUserDiscount(UserDiscount userDiscount){
         userDiscount.preUpdate();
        boolean b = userDiscountService.updateById(userDiscount);
         return TableResult.Result(b);
     }

     @RequestMapping("/findUserDiscountOne")
     @ResponseBody
     public TableResult findUserDiscountOne(UserDiscount userDiscount){

        EntityWrapper<UserDiscount> wrapper = userDiscount.getQueryWrapper();

        if(userDiscount.getId()!=null){
            wrapper.eq("id",userDiscount.getId());
        }
        //Todo

        UserDiscount result = userDiscountService.selectOne(wrapper);

		return TableResult.OKResult(result);
     }

     @RequestMapping("/findUserDiscountList")
     @ResponseBody
     public TableResult findUserDiscountList(UserDiscount userDiscount){

        EntityWrapper<UserDiscount> wrapper = userDiscount.getQueryWrapper();

        Page<UserDiscount> page = userDiscount.getPageInfo();

        List<UserDiscount> list = userDiscountService.selectUserDiscountList(page,userDiscount);
         page.setRecords(list);
		return TableResult.OKResult(page);

     }

     @RequestMapping("/deleteUserDiscount")
     @ResponseBody
     public TableResult deleteUserDiscount(UserDiscount userDiscount){
        userDiscount.preUpdate();
        boolean b = userDiscountService.deleteById(userDiscount.getId());
        return TableResult.Result(b);
     }

}
